<?php
defined('_JEXEC') or die('Restricted access');
$img_dir = JPATH_SITE.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'fileupload'.DIRECTORY_SEPARATOR;
$img_path = JURI::root(true).'/images/fileupload/';
$title = ($this->id)?"Sửa thông tin theo dõi mày":"Thêm thông tin theo dõi máy";

$cache_dir = JPATH_COMPONENT.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;

$cache_filename_linhkien = $cache_dir."linhkien.php";
if(JFile::exists($cache_filename_linhkien))
{
	include($cache_filename_linhkien);
	$cache_data_linhkien = $cache_linhkien;
}else $cache_data_linhkien = array();
?>
<form class='form' id="form_create_repair" method="post" action="index.php">
<div class='tab_content' id="tab_create_repair">
	<div class='container-fluid container_root margin10'>
		<div class='row-fluid'>
			<div class='widget widget-padding span12'>
				<div class='widget-header'>
					<i class="icon-plus"></i>
					<h5><?php echo $title ?></h5>
				</div>
				<div class='widget-body'>
								
					
						<div class='row-fluid'>
							<div class='span12'>
								<button type="submit" class='btn btn-primary'>
									<i class='icon-ok icon-white'></i>
									<?php echo JText::_("COM_KETNOI_SAVEBTN") ?>
								</button>
								
								<a type="submit" href="#repair" class='btn'>
									<i class='icon-reorder icon-white'></i>
									Danh sách
								</a>
							</div>
						</div>
						
						<div class="row-fluid margin10">
							<div class='span12'>
								<div class="row-fluid">
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Chọn serial
												<em>*</em>
											</label>
					                        <div class="controls row-fluid chosen_nocreate">
					                            <select  data-placeholder="Chọn máy" id="serial" name="inventory_id">
					                            	<option value="">Chọn máy</option>
					                            	<?php foreach ($this->serials as $serial): ?>
					                            		<?php $selected = $serial->serial == $this->row->inventory_id?"selected":"" ?>
					                            		<option data-row='<?php echo json_encode($serial) ?>' <?= $selected ?> value="<?php echo $serial->id ?>" >
					                            			<?php echo $serial->serial ?>
					                            		</option>
					                            	<?php endforeach; ?>
					                            </select>
				
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Mã máy
											</label>
					                        <div class="controls row-fluid">
					                            <input type="text" readonly class="span12" id="mamay"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Tên máy
											</label>
					                        <div class="controls row-fluid">
					                            <input type="text" readonly class="span12" id="tenmay"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Số counter đã dùng
											</label>
					                        <div class="controls row-fluid">
					                            <input type="text" readonly class="span12" id="socounterdadung"/>
					                        </div>
				                        </div>
									</div>
								</div>
								<div class="row-fluid">
									
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Nhân viên lắp đặt
												<em>*</em>
											</label>
					                        <div class="controls row-fluid chosen_multiple chosen_table chosen_quickcreate">
					                            <select multiple id="employee" name="employee_id[]">
					                            	<?php foreach ($this->employee as $employee): ?>
					                            		<?php $selected = $employee->id == $this->row->employee_id?"selected":"" ?>
					                            		<option <?= $selected ?> value="<?php echo $employee->id ?>" data-ten="<?php echo $employee->hoten ?>" data-ma="<?php echo $employee->ma ?>">
					                            			<?php echo $employee->ma ?> - <?php echo $employee->hoten ?>
					                            		</option>
					                            	<?php endforeach; ?>
					                            </select>
					                            <a class='btn btn-info fix-btn' onclick='showModalCreateNhanvien("employee")'>
													<i class='icon icon-plus'></i>
												</a>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Số counter
											</label>
					                        <div class="controls row-fluid custom">
					                            <input type="text" class="span12" id="socounter" name="socounter"/>
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Tên khách hàng
											</label>
					                        <div class="controls row-fluid">
					                            <input readonly type="text" class="span12" id="tenkhachhang" />
					                        </div>
				                        </div>
									</div>
									
									<div class="span3">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Mã khách hàng
											</label>
					                        <div class="controls row-fluid">
					                            <input readonly type="text" class="span12" id="makhachhang" />
					                            <input type="hidden" name="customer_id" id="idkhachhang" />
					                        </div>
				                        </div>
									</div>
								</div>	
								
								<div class="row-fluid">
									<div class="span6">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Mã lỗi
												<em>*</em>
											</label>
					                        <div class="controls row-fluid chosen_multiple chosen_table chosen_quickcreate">
					                            <select multiple id="maloi" name="maloi_id[]">
					                            	<?php foreach ($this->maloi as $maloi): ?>
					                            		<?php $selected = $maloi->id == $this->row->maloi_id?"selected":"" ?>
					                            		<option <?= $selected ?> value="<?php echo $maloi->id ?>" data-ten="<?php echo $maloi->ten ?>" data-ma="<?php echo $maloi->ma ?>">
					                            			<?php echo $maloi->ma ?> - <?php echo $maloi->ten ?>
					                            		</option>
					                            	<?php endforeach; ?>
					                            </select>
					                            <a class='btn btn-info fix-btn' onclick='showModalCreatemaloi_popup(this)'>
													<i class='icon icon-plus'></i>
												</a>
					                        </div>
				                        </div>
									</div>
									
									<div class="span6">
										<div class="control-group">
				                          	<label class="control-label" for="name">
				                          		Ghi chú
											</label>
					                        <div class="controls row-fluid">
					                            <textarea name="description"></textarea>
					                        </div>
				                        </div>
									</div>
								</div>
							</div>
						</div>	
				</div>
				
			</div>
		</div>
		<br>
		<div class="row-fluid tinhtranglinhkien">
			<div class='widget widget-padding span12'>
			<div class='widget-header'>
				<i class="icon-plus"></i>
				<h5>Tình trạng linh kiện</h5>
			</div>
			<div class='widget-body'>
				<div class="row-fluid">
					<div class="span12">
						<table id="tinhtrang_linhkien" class="k-grid custom k-widget">
							<thead class="k-grid-header">
								<tr>
									<th class="k-header" width="10%">Mã linh kiện</th>
									<th class="k-header" width="20%">Tên linh kiện</th>
									<th class="k-header" width="10%">Số tháng bảo hành</th>
									<th class="k-header" width="10%">Số dung lượng bảo hành</th>
									<th class="k-header" width="10%">Tuổi thọ</th>
									<th class="k-header" width="10%">Nhà cung cấp</th>
									<th class="k-header" width="15%">Tình trạng</th>
									<th class="k-header" width="15%"></th>
								</tr>
							</thead>
							<tbody></tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
	<br>
		<div class="row-fluid thaythelinhkien">
			<div class='widget widget-padding span12'>
			<div class='widget-header'>
				<i class="icon-plus"></i>
				<h5>Thay thế linh kiện</h5>
			</div>
			<div class='widget-body'>
				<div class="row-fluid">
					<div class="span6">
						<div class="control-group">
                          	<label class="control-label" for="name">
                          		Danh sách linh kiện
							</label>
	                        <div class="controls row-fluid">
	                        	<div class="chosen_multiple chosen_table chosen_quickcreate ">
								    <select data-placeholder="Mã linh kiện" class="linhkien_select" multiple>
								    	<?php foreach ($cache_data_linhkien as $linhkien): ?>
								        	<option data-json='<?php echo json_encode($linhkien) ?>' value="<?php echo $linhkien["id"] ?>" data-ten="<?php echo $linhkien["ten"] ?>" data-ma="<?php echo $linhkien["ma"] ?>">
								            	<?php echo $linhkien["ma"] ?> - <?php echo $linhkien["ten"] ?> 
								            </option>
								        <?php endforeach; ?>
								    </select>
									<a class='btn btn-info fix-btn' onclick='showModalCreateLinhkien_popup(this)'>
										<i class='icon icon-plus'></i>
									</a>
								</div>	
	                        </div>
                        </div>
					</div>
					<div class="span6">
						<div class="control-group">
                          	<label class="control-label" for="name">
                          		&nbsp;
							</label>
	                        <div class="controls row-fluid">
	                        	<a class="btn btn-info" onclick='repair_addlinhkien(<?php echo json_encode($this->vendor) ?>)'>
									<i class="icon-plus icon-white"></i>
									Thêm
								</a>
	                        </div>
                        </div>
								
					</div>
				</div>
				<div class="row-fluid">
					<div class="span12">
						<table id="table_linhkien" class="k-grid custom k-widget">
							<thead class="k-grid-header">
								<tr>
									<th class="k-header">Mã linh kiện</th>
									<th class="k-header">Tên linh kiện</th>
									<th class="k-header">Số tháng bảo hành</th>
									<th class="k-header">Số dung lượng bảo hành</th>
									<th class="k-header">Tuổi thọ</th>
									<th class="k-header">Nhà cung cấp</th>
									<th class="k-header"></th>
								</tr>
							</thead>
							<tbody></tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
	<input type="hidden" name="option" value="com_ketnoi" />
	<input type="hidden" name="view" value="repair" />
	<input type="hidden" name="task" value="repair.save" />
	<input type="hidden" name="layout" value="create" />
	<input type="hidden" name="tmpl" value="raw" />
	<?php if($this->id): ?>
	<input type="hidden" name="id" value="<?= $this->id ?>" />
<?php endif; ?>
</form>
<script>
	<?php if($this->id): ?>
		//setHash("edit_repair",<?= json_encode(array("id"=>$this->id)) ?>);
	<?php endif; ?>
</script>
